package com.slipper.ai.controller;

import com.slipper.ai.service.ChatService;
import com.slipper.system.ai.bo.AiApplicationBO;
import com.slipper.system.ai.service.AiApplicationService;
import com.slipper.util.*;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/ai/application")
public class AiApplicationApiController {
    @Resource
    private ChatService chatService;
    @Resource
    private AiApplicationService applicationService;

    @PostMapping(value = "/queryBySystemId")
    public String queryBySystemId(@RequestBody AiApplicationBO bo) {
        if(Tool.isBlank(bo.getSystemId())) {
            return ResultUtil.failureResult("数据获取失败！");
        }
        return ResultUtil.successResult(applicationService.queryBySystemId(bo));
    }

    @PostMapping(value = "/chat")
    public String chat(@RequestBody AiApplicationBO bo) {
        AiApplicationBO app = applicationService.queryBy(bo.getId());
        app.setQuery(bo.getQuery());
        return chatService.chat(app, false);
    }
}
